/*
 * @Author: your name
 * @Date: 2024-04-19 16:22:27
 * @LastEditTime: 2024-04-19 16:30:18
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \.leetcode\101.对称二叉树.cpp
 */
/*
 * @lc app=leetcode.cn id=101 lang=cpp
 *
 * [101] 对称二叉树
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
   bool compare(TreeNode* left, TreeNode* right){
        if(left == nullptr && right == nullptr){
            return true;
        }
        else if(left == nullptr || right == nullptr){
            return false;
        }else if(left->val != right->val){
            return false;
        }   
        bool outside = compare(left->left, right->right);
        bool inside = compare(left->right, right->left);
        return (outside && inside); 
    }
    bool isSymmetric(TreeNode* root) {
        if(root == nullptr) return false;
        bool res = compare(root->left,root->right);
        return res;
    }
};
// @lc code=end

